package org.yookiee.support.toolkits;

/**
 * company -
 * FileName DataTypeToolkit
 * Package org.yookiee.support.toolkits
 * Description
 * author cpstory_a
 * create 2023-12-06 9:11
 * version V1.0
 */
public class DataTypeToolkit {

    /**
     * 判断为简单数据类型
     * @param obj
     * @return
     */
    public static boolean isSimpleType(Object obj) {
        if (obj == null) {
            return false;
        }

        Class<?> clazz = obj.getClass();
        return clazz.isPrimitive() ||
                clazz.isAssignableFrom(Boolean.class) ||
                clazz.isAssignableFrom(Character.class) ||
                Number.class.isAssignableFrom(clazz) ||
                clazz.isAssignableFrom(String.class);
    }

    /**
     * 判断为非字符串类型的简单数据类型
     * @param obj
     * @return
     */
    public static boolean isSimpleTypeWithoutString(Object obj) {
        if (obj == null) {
            return false;
        }

        Class<?> clazz = obj.getClass();
        return clazz.isPrimitive() ||
                clazz.isAssignableFrom(Boolean.class) ||
                clazz.isAssignableFrom(Character.class) ||
                Number.class.isAssignableFrom(clazz);
    }

    /**
     * 判断为非字符串类型的简单数据类型
     * @param obj
     * @return
     */
    public static boolean isString(Object obj) {
        if (obj == null) {
            return false;
        }

        Class<?> clazz = obj.getClass();
        return clazz.isAssignableFrom(String.class);
    }
}
